class Solution {
public:
    bool IsPopOrder(vector<int> pushV,vector<int> popV) {
    	int idxV = 0;
    	for(int i = 0 ; i < pushV.size() ; ++i)
    	{
    		if(pushV[i] != popV[idxV])
    		{
    			s.push(pushV[i]);
    			continue;
    		}
    		else
    		{
    			++idxV;
    			while(!s.empty() && idxV < popV.size() && s.top() == popV[idxV])
    			{
    				s.pop();
    				++idxV;
    			}
    		}
    	}
    	while(!s.empty() && idxV < popV.size() && s.top() == popV[idxV])
		{
			s.pop();
			++idxV;
		}
		if(!s.empty())
			return false;
		return true;
    }
private:
	stack<int> s;
};